import sys
import re

def count_characters(file_path):
    """统计字符数（包括所有字符，如字母、数字、标点、空格等）"""
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
        return len(content)

def count_words(file_path):
    """统计单词数（以空格、标点等分隔的连续字母序列，仅考虑由字母组成的单词）"""
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
        # 匹配由字母组成的单词，不区分大小写
        words = re.findall(r'[a-zA-Z]+', content)
        return len(words)

def count_sentences(file_path):
    """统计句子数（以句号、问号、感叹号结尾的为一个句子）"""
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()
        # 匹配以句号、问号、感叹号结尾的句子，考虑可能的空格
        sentences = re.findall(r'[^\n.!?]+[.!?]\s*', content)
        return len(sentences)

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("命令格式错误，正确格式：wc.exe [参数] [文件名]")
        print("参数说明：-c 统计字符数；-w 统计单词数；-s 统计句子数")
        sys.exit(1)
    
    param = sys.argv[1]
    file_name = sys.argv[2]
    
    if param == '-c':
        char_count = count_characters(file_name)
        print(f"字符数：{char_count}")
    elif param == '-w':
        word_count = count_words(file_name)
        print(f"单词数：{word_count}")
    elif param == '-s':
        sentence_count = count_sentences(file_name)
        print(f"句子数：{sentence_count}")
    else:
        print("无效参数，参数说明：-c 统计字符数；-w 统计单词数；-s 统计句子数")
